﻿@using Commonality.ReturnView
@using ModelToDto
@model PagingData<UsersDTO>
<h1>用户管理</h1>

  @using (Html.BeginForm("Index", "User", FormMethod.Get, new { @class = "row g-3" }))
{
    <p></p>
    <div class="row mb-3">
        <label class="col-md-2 col-form-label">用户类型</label>
        <div class="col-md-2 col px-md-1">
            @Html.DropDownList("userType", ViewData["userTypeEnum"] as IList<SelectListItem>, new { @class = "btn btn-secondary btn-lg dropdown-toggle form-select", @onchange = "$('form').submit()" })
        </div>
        <label class="col-form-label col px-md-4">用户状态</label>
        <div class="col-md-2 col px-md-1">
            @Html.DropDownList("userStatu", ViewData["userStatuEnum"] as IList<SelectListItem>, new { @class = "btn btn-secondary btn-lg dropdown-toggle form-select", @onchange = "$('form').submit()" })
        </div>
        <label class="col-md-2 col-form-label col px-md-4">性别</label>
        <div class="col-md-2 col px-md-1">
            @Html.DropDownList("userGender", ViewData["genderEnum"] as IList<SelectListItem>, new { @class = "btn btn-secondary btn-lg dropdown-toggle form-select", @onchange = "$('form').submit()" })
        </div>  
    </div>
    <div class="row mb-3 col px-md-2">
        <label class="col-md-2 col-form-label">关键字</label>
        <div class="col-md-3 col px-md-2">
            @Html.TextBox("searchString", @Model.SearchString, new { @class = "form-control", @placeholder = "关键字" })
        </div>
        <div class="col-md-3">
            <button type="submit" class="btn btn-primary mb-3">查询</button>
        </div>
        <div class="col-md-3">
            <a href="/User/AddOrEdit">新增后台用户</a>
        </div>
    </div>
    <div class="mb-7 row" id="partialajaxlist" style="width:100%">
        <div class="div-table">
            @await Html.PartialAsync("ParUserList", Model.DataList)
        </div>
        <Paging total="@Model.RecordCount"
                page-index="@Model.PageIndex"
                page-size="@Model.PageSize"
                route-url="/User/Index"
                query="">
        </Paging>
    </div>
}

@section scripts {
    <script type="text/javascript">
       
          function ajaxDelete(id) {
                 $.ajax({
                      type: "Delete",
                      url: '/User/Delete',
                      data: { id: id },
                      success: function (data) {
                          if (data.success ===true) {
                                $("#myConfirm").modal("hide");
                                 location.reload(true);
                          }
                          else{
                              alert("删除失败了");
                          }
                      },
                      error: function (XMLHttpRequest, textStatus, errorThrown) {
                          alert(errorThrown);
                      }
                  });
          }

          ///
          function confirm(fun, params) {
              if ($("#myConfirm").length > 0) {
                  $("#myConfirm").remove();
              }
              var html = "<div class='modal fade' id='myConfirm' >"
                      + "<div class='modal-backdrop in' style='opacity:0; '></div>"
                      + "<div class='modal-dialog' style='z-index:2901; margin-top:60px; width:400px; '>"
                      + "<div class='modal-content'>"
                      + "<div class='modal-header'  style='font-size:16px; '>"
                      + "<span class='glyphicon glyphicon-envelope'>&nbsp;</span>信息！<button type='button' class='close' data-dismiss='modal'>"
                      + "<span style='font-size:20px;  ' class='glyphicon glyphicon-remove'></span><tton></div>"
                      + "<div class='modal-body text-center' id='myConfirmContent' style='font-size:18px; '>"
                      + "是否确定要删除？"
                      + "</div>"
                      + "<div class='modal-footer ' style=''>"
                      + "<button class='btn btn-danger ' id='confirmOk' >确定<tton>"
                      + "<button class='btn btn-info ' id='cancel' data-dismiss='modal'>取消<tton>"
                      + "</div>" + "</div></div></div>";
              $("body").append(html);

              $("#myConfirm").modal("show");

              $("#confirmOk").on("click", function() {
                  $("#myConfirm").modal("hide");
                  fun(params); // 执行函数
              });

               $("#cancel").on("click", function() {
                  $("#myConfirm").modal("hide");
              });
        }

    </script>
}

